package com.jelly.web.modules.monitor.log.controller;

import com.jelly.common.constant.GlobalConstant;
import com.jelly.common.excel.ReportExcel;
import com.jelly.common.note.OperationLog;
import com.jelly.common.web.page.LayuiTableInfo;
import com.jelly.web.share.base.controller.BaseController;
import com.jelly.web.modules.monitor.log.domain.OperLogAndUser;
import com.jelly.web.modules.monitor.log.service.IOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @创建人 ql
 * @创建时间 2018-09-05 19:36
 * @项目名称 jelly
 * @功能描述: 操作日志模块
 *          1丶获取操作日志列表
 *          2丶导出操作日志
 **/
@Controller
@RequestMapping("/admin/monitor/operlog")
public class OperLogController extends BaseController {

    @Autowired
    private IOperLogService operLogService;

    /**
     * 操作日志列表跳转
     * @return
     */
    @GetMapping
    public String getOperLogList(){

        //获取字典详情
        getDictionary();
        //获取该用户可访问的按钮详情
        getButton();

        return adminOperLog("/list");

    }

    /**
     * 获取操作日志列表
     * @param operLogAndUser
     * @return
     */
    @PostMapping
    @ResponseBody
    public LayuiTableInfo getOperLogList(OperLogAndUser operLogAndUser){

        getPageHelper();

        return getPageHelper(operLogService.getOperLog(operLogAndUser));

    }

    /**
     * 导出操作日志
     * @param operLogAndUser
     * @return
     */
    @GetMapping("/export")
    @OperationLog(name = "操作日志模块",value = GlobalConstant.EXPORT)
    public void export(HttpServletRequest req, HttpServletResponse resp, OperLogAndUser operLogAndUser){
        List<OperLogAndUser> list = operLogService.getOperLog(operLogAndUser);
        ReportExcel reportExcel = new ReportExcel();
        try {
            reportExcel.excelExport(list,"操作日志Excel",OperLogAndUser.class,1,resp,req);
        }catch (Exception e){
        }
    }

}
